local skill = fk.CreateSkill {
  name = "lvshi__rockfall_skill",
}
local ls = require "packages/lvshi/utility"

Fk:loadTranslationTable{
  ["#lvshi__rockfall_skill_throw"] = "你可弃置一张黑色牌令%src额外失去1点体力",
}

skill:addEffect("cardskill", {
  prompt = "#lvshi__rockfall_skill",
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card)
    return to_select:isKongcheng() or to_select.chained
  end,
  target_filter = Util.CardTargetFilter,
  on_use = function(self, room, use)
    local choice = ls.strategytrickuse(use.from, use.card, "rockfall_scheme", "rockfall_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    room:loseHp(to, 1, skill.name)
    if effect.extra_data.strategy == "rockfall_scheme" then
      if not to.chained then
        to:setChainState(true)
      elseif not to:isKongcheng() then
        room:askToDiscard(to, {
          min_num = 1,
          max_num = 1,
          include_equip = false,
          skill_name = skill.name,
          cancelable = false,
        })
      end
    elseif effect.extra_data.strategy == "rockfall_courage" and to:isKongcheng() and to.chained then
      local params = {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = skill.name,
        cancelable = true,
        pattern = ".|.|spade,club",
        prompt = "#lvshi__rockfall_skill_throw:"..to.id
      }
      local cards = room:askToDiscard(from, params)
      if #cards > 0 then
        room:loseHp(to, 1, skill.name)
      end
    end 
  end,
})

return skill